package html.states.login;
import html.util.Container;
import js.Dom;
import js.Lib;

/**
 * ...
 * @author Felipe Manga
 */

class Login extends Container
{

	public function new() 
	{
		super();
	}
	
	@pipe var server_logIn:Int;
	
	@slot function server_checkRegisterUser( user:String, newPass:String, confPass:String, newMail:String, confMail:String ):Void
	{
		if ( newPass != confPass )
		{
			Lib.alert("Passwords do not match!");
			return;
		}
		
		if ( newMail != confMail )
		{
			Lib.alert("E-mails do not match!");
			return;
		}
		
		this.signalUp( "server_registerUser", [user, newMail, newPass] );
	}
	
	function notify( msg:String ):Void
	{
		this.get("errmsg").innerHTML = "";
		this.get("msg").innerHTML = msg;
	}

	function error( msg:String ):Void
	{
		this.get("errmsg").innerHTML = msg;
		this.get("msg").innerHTML = "";
	}
	
	@slot function registrationFailed( msg:String ) error( "Registration failed: " + msg )
	@slot function registrationSuccess() notify( "Registration complete. You can now log in with your new account." )
	
	@slot function loginFailed( msg:String ) this.get("errmsg").innerHTML = "Login failed: " + msg
	@slot function loginSuccess():Void this.signalUp("server_getUserData", [])
}